<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\CarModel;
use App\Models\GoodsModel;
use Illuminate\Support\Facades\DB;
class CarController extends Controller
{



  public function cars()
    {
        //
       $goods=CarModel::paginate(3);
        
      return view("Admin/cares/goods")->with("product",$goods);

    }
    public function xd()
    {
        //
       
        
      return view("Admin/cares/xd");

    }
    public function cg(Request $request,$id)
    {
        //
      $carid=$request->route('id');

       $car1=DB::table('cars')->where('carid',$carid)->first();
        
      return view("Admin/cares/index")->with("car",$car1);

    }
       
    
    public function addcar(Request $request,$id)
    {
     // dd($id);
      $car2=new CarModel;
      $car=DB::table('cars')->get();
      $productid=$request->route('id');



        $goos=DB::table('goods')->where('prductid',$productid)->first();
        
        $car1=DB::table('cars')->where('productid',$productid)->first();
       
       if(empty($car1)){
         $data["username"]=("小明");
         $data["productid"]=$productid;
        $data["productname"]=$goos->productname;
        
        $data["price"]=$goos->price;
        $data["nums"]=1;
        $car2->add($data);
      
        return redirect("/cars");

       }else{

        $carid=$car1->carid;
        $data["nums"]=$car1->nums+1;
        $car2->update1($carid,$data);
        return redirect("/cars");
       }
      }

      // dd($productid);
        

    

}
